package model

import (
	"fmt"
	"qabx.net/safe-app-center/pkg/utils"
	"time"
)

type TblScanRecords struct {
	UserId     int    `json:"user_id,omitempty"`
	GatewayId  int    `json:"gateway_id,omitempty"`
	ScanId     string `json:"scan_id,omitempty"`
	CreateTime string `json:"create_time,omitempty"`
	UpdateTime string `json:"update_time,omitempty"`
	IsDel      int    `json:"is_del,omitempty"`
	State      int    `json:"state"`
	ScanScope  int    `json:"scan_scope"`
}

func (s *TblScanRecords) UpdateScanRecord(scanId string, scanScope int) error {
	newRes := &TblScanRecords{}
	newRes.State = 1
	newRes.ScanScope = scanScope
	newRes.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
	dbClient, _ := utils.GetDbClient()
	scanScopeExpress := fmt.Sprintf("scan_scope - %d", scanScope)
	_, err := dbClient.Client.Cols("state", "update_time").Where("scan_id = ?", scanId).SetExpr("scan_scope", scanScopeExpress).Update(newRes)
	return err
}
